package com.jingzhi.huimiao;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TextView;

import com.jingzhi.huimiao.utils.SQLdm;

public class DatabActivity extends Activity { 
	  /** Called when the activity is first created. */
	  @Override
	  public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.activity_datab);
	    
	    //打开数据库输出流
	    SQLdm s = new SQLdm();
	    SQLiteDatabase db =s.openDatabase(getApplicationContext()); 
	    
	    TextView textv = (TextView) findViewById(R.id.textv);
	    TextView tv_translation = (TextView) findViewById(R.id.tv_translation);
	    TextView tv_example = (TextView) findViewById(R.id.tv_example);
	    //查询数据库中testid=1的数据
	    Cursor cursor = db.rawQuery("select * from word where id=?", new String[]{"1"}); 
	    String name = null;
	    String translation = null;
	    String example = null;
	    
	    if(cursor.moveToFirst()){  
	    	name = cursor.getString(cursor.getColumnIndex("word_name"));
	    	translation = cursor.getString(cursor.getColumnIndex("word_translation"));
	    	example = cursor.getString(cursor.getColumnIndex("word_example"));
	    }  
	    //这是一个TextView，把得到的数据库中的name显示出来.
	    textv.setText(name);
	    tv_translation.setText(translation);
	    tv_example.setText(example);
	    cursor.close();  
	  }
	}
